package com.qk.management.controller;


import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.course.CourseDTO;
import com.qk.management.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/courses")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping
    public Result getCourses(CourseDTO courseDto) {
        PageResult<CourseDTO> pageresult = courseService.getCourses(courseDto);
        return Result.success(pageresult);
    }

    @DeleteMapping("/{id}")
    public Result deleteCourse(@PathVariable("id") Integer id) {
        courseService.deleteCourse(id);
        return Result.success();
    }

    @PostMapping
    public Result addCourse(@RequestBody CourseDTO courseDto) {
        courseService.addCourse(courseDto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getCourseById(@PathVariable("id") Integer id) {
        courseService.getCourseById(id);
        return Result.success();
    }

    @PutMapping
    public Result updateCourse(@RequestBody CourseDTO courseDto) {
        courseService.updateCourse(courseDto);
        return Result.success();
    }

    /*查询所有课程数据*/
    @GetMapping("/list")
    public Result list() {
        return Result.success(courseService.list());
    }
}
